package rmmk.algorithms.similarityMeasures.utils;

import java.util.Map.Entry;
import java.util.TreeMap;                                       

import rmmk.framework.datasources.Document;

public class SpecifiedWordsFinder {

	public static TreeMap<String, Integer> calculate(Document document,
			TreeMap<String,Integer> mostFrequentWords) {

		TreeMap<String, Integer> specifiedWords = new TreeMap<String, Integer>();
		
		for (Entry<String, Integer> entry : mostFrequentWords.entrySet()){
			specifiedWords.put(entry.getKey(), 0);
		}
				
		for (String word : document.getExtractedWords()) {

			checkIfContainsAndAdd(word, specifiedWords);

		}

		return specifiedWords;
	}

	private static void checkIfContainsAndAdd(String word,
			TreeMap<String, Integer> map) {

		Integer number = map.get(word);

		if (number != null) {
			int nr = number + 1;
			map.put(word, nr);

		}
	}
}